package com.yingdong.thread;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.yingdong.gateserver.innter.service.ConfigService;
import com.yingdong.gateserver.net.GameSession;
import com.yingdong.gateserver.opcode.Dispatcher;

public class GateServerThreadFactory {
	static Log logger = LogFactory.getLog(GateServerThreadFactory.class);
	private static Thread heartBeartThread;

	public static void init() {
		heartBeartThread = new Thread(new Runnable() {

			@Override
			public void run() {
				while (true) {

					try {
						for (GameSession session : Dispatcher.sessionMap.values()) {
							if (session.getTimestamp() != 0) {
								if (System.currentTimeMillis() - session.getTimestamp() > ConfigService.getPropertyInt("game.timeout")) {
									session.getChannel().disconnect();
								}
							}
						}
						Thread.sleep(30 * 1000);
					} catch (Exception e) {
						logger.error("",e);
					}

				}

			}
		});
		heartBeartThread.start();
	}
}
